package com.yn.pet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yn.pet.bus.dao.DeviceInfoDao;
import com.yn.pet.bus.entity.DeviceInfo;
import com.yn.pet.service.DeviceInfoService;
import io.jsonwebtoken.lang.Assert;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 设备信息表(DeviceInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-07-09 12:00:46
 */
@Service("deviceInfoService")
public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfo> implements DeviceInfoService {

    @Override
    public DeviceInfo getByImei(String imei) {
        Assert.hasText(imei, "IMEI号不能为空");
        return this.list(new LambdaQueryWrapper<DeviceInfo>().eq(DeviceInfo::getImei, imei)).stream().findAny().orElse(null);
    }

    @Override
    public List<DeviceInfo> listByImei(Collection<String> imeis) {
        Assert.notEmpty(imeis, "IMEI号不能为空");
        return this.list(new LambdaQueryWrapper<DeviceInfo>().in(DeviceInfo::getImei, imeis));
    }

    @Override
    public List<DeviceInfo> listLikeDeviceName(String deviceName) {
        Assert.hasText(deviceName, "设备名称不能为空");
        return this.list(new LambdaQueryWrapper<DeviceInfo>().like(DeviceInfo::getDeviceName, deviceName));
    }

    @Override
    public List<DeviceInfo> listLikeImei(String imei) {
        Assert.hasText(imei, "IMEI号不能为空");
        return this.list(new LambdaQueryWrapper<DeviceInfo>().like(DeviceInfo::getImei, imei));
    }
}

